﻿using AMEE.BeinControl;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeinDemo1.ViewModel
{
    /// <summary>
    /// 
    /// </summary>
    class BeinVM : ViewModelBase<Bein>
    {

        /// <summary>
        /// Gets the state of the Leg.
        /// </summary>
        /// <remarks>
        /// OnPropertyChanged wird indirekt durch Bein.StateChanged ausgelöst (siehe ctor).
        /// </remarks>
        public BeinState State {
            get {
                return this.Model.State;
            }
            //set {
            //    /*do nothing*/
            //}
        }

        public BeinVM(Bein model) : base(model) {
            if (model == null)
                throw new ArgumentNullException("model");
            model.StateChanged += (obj, evArg) => this.OnPropertyChanged("State");
        }

    }

    /// <summary>
    /// 
    /// </summary>
    class BeinListVM : ViewModelBase
    {
        ObservableCollection<BeinVM> _beinVMs;

        /// <summary>
        /// Gets or sets the bein ViewModels.
        /// </summary>
        /// <value>
        /// The Bein ViewModel.
        /// </value>
        public ObservableCollection<BeinVM> BeinVMs {
            get { return _beinVMs; }
            set {
                if (_beinVMs != value) {
                    _beinVMs = value;
                    this.OnPropertyChanged("BeinVMs");
                }
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="BeinListVM"/> class.
        /// </summary>
        public BeinListVM() : base() {
            _beinVMs = new ObservableCollection<BeinVM>();
            _beinVMs.CollectionChanged += _beinVMs_CollectionChanged;
        }

        /// <summary>
        /// Handles the CollectionChanged event of the _beinVMs control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
        void _beinVMs_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) {
            //switch (e.Action) {
            //    case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
            //        foreach (BeinVM viewModel in e.NewItems) {

            //        }
            //        break;
            //    case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
            //        break;
            //    case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
            //        break;
            //    case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
            //        break;
            //    case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
            //        break;
            //    default:
            //        break;
            //}
        }
    }
}
